package com.zhuge_new.Adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhuge_new.R;
import com.zhuge_new.bean.PlandetailsBean;
import com.zhuge_new.untils.NumberUtil;

import java.util.List;

/**
 * Created by lenovo on 2018-09-28.
 */

public class PlandetailsAdapter extends BaseQuickAdapter<PlandetailsBean.RepaymentsBean,BaseViewHolder> {

    private Context context;
    private PlandetailsBean plandetailsBean;
    private String cardNo;
    public PlandetailsAdapter(Context context, PlandetailsBean plandetailsBean, String cardNo) {
        super(R.layout.item_plandetails, plandetailsBean.getRepayments());
        this.context=context;
        this.plandetailsBean=plandetailsBean;
        this.cardNo=cardNo;
    }


    @Override
    public int getItemCount() {
        return super.getItemCount()+getHeaderLayoutCount();
    }

    @Override
    protected void convert(BaseViewHolder helper, PlandetailsBean.RepaymentsBean item) {
        String RepaymentType=item.getRepaymentType();
        if (RepaymentType.equals("智能还款")){
            helper.setText(R.id.check_item_pattern,"还款计划");
        }else {
            helper.setText(R.id.check_item_pattern,item.getRepaymentType());
        }
        if (RepaymentType.equals("智能还款")){
            helper.setText(R.id.check_item_rate,"[费率"+NumberUtil.saveRound(item.getRate(),1)+"元]");
        }else {
            helper.setText(R.id.check_item_rate,"[费率"+NumberUtil.main(item.getRate())+"]");
        }
        helper.setText(R.id.check_item_tail,"尾号"+cardNo);

        String time=item.getRepaymentDay();
        if (time.isEmpty()){
            return;
        }else {
            helper.setText(R.id.check_item_data,time);
        }
        String repaymentType=item.getRepaymentType();
        ImageView check_item_logo=helper.getView(R.id.check_item_logo);
        if (repaymentType.equals("智能还款")){
            helper.setText(R.id.check_item_money,"+"+ NumberUtil.saveRound(item.getRepaymentSum(),2));
            check_item_logo.setImageResource(R.mipmap.huankuanlogo);
        }else if (repaymentType.equals("收款")){
            helper.setText(R.id.check_item_money,"+"+NumberUtil.saveRound(item.getRepaymentSum(),2));
            check_item_logo.setImageResource(R.mipmap.huankuanlogo);
        }else {
            helper.setText(R.id.check_item_money,"-"+NumberUtil.saveRound(item.getRepaymentSum(),2));
            check_item_logo.setImageResource(R.mipmap.shoukuanlogo);

        }

        String status=item.getStatus();
        if (status.equals("1")){
            helper.setText(R.id.check_item_state,"交易成功");
        }else if (status.equals("0")){
            helper.setText(R.id.check_item_state,"交易失败");
        }else if (status.equals(-1)){
            helper.setText(R.id.check_item_state,"计划未执行");
        }else {
            helper.setText(R.id.check_item_state,"执行中");
        }

    }
}
